<?php

class Catalogue_Model_Attribute_Enum_Item extends Catalogue_Model_Object_Abstract {

    /**
     * Тип объекта
     * @var string
     */
    protected $_objectType = Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM;

	static function getInstance($identity) {
		$storage = self::getDefaultStorage(Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM);
		return $storage->getOne($identity);
	}

	static function create($data) {
		$storage = self::getDefaultStorage(Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM);
		return $storage->create($data);
	}

    static function getAll(Catalogue_Model_Attribute_Enum $attr = null, $where = null, $order = null,
                           $limit = null, $offset = null, $offsetByPage = false) 
    {
        $storage = self::getDefaultStorage(Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM);
        return $storage->getAll($attr, $where, $order, $limit, $offset, $offsetByPage);
    }

	function save() {
		//целочисленный индекс значения
		$filter = self::getPlugin('filter', 'ValueIndex');
		$this->_data['value_id'] = $filter->filter($this->_data['value']);

		$storage = $this->_initStorage(Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM);
		return $storage->save($this);
	}

	function delete() {
		$storage = $this->_initStorage(Catalogue_Model_Object_Abstract::T_ATTRIBUTE_ENUM_ITEM);
		return $storage->delete($this);
	}

	function getAttribute() {
		$attrId = $this->getAttributeId();
		return Catalogue_Model_Attribute_Enum::getInstance($attrId);
	}

	function getAttributeId() {
		return (int)$this->_data['attr_id'];
	}

	function setValue($value) {
		$this->_data['value'] = (string)$value;
	}

	function getValue() {
		return $this->_data['value'];
	}

}

?>